// pages/main/single.js
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var config = require('../../config')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    introduce: [],//[{ typevalue: '/images/introduce-default.jpg',seqid:'1' }], 
    noticeList: [],//[{ typename: 'test公告111' }],
    functions: [],//[{ typename: '信息发布', seqid: '1' }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getIntroduce()
    this.getNotice()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMenu()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // toFunctions(data){
  //   console.log(data)
  //   // wx.redirectTo({
  //   //   url: '/pages/start/index?functype='
  //   // })
  // },
  //获取介绍信息
  getIntroduce() {
    var that = this
    qcloud.request({
      url: `${config.service.host}/weapp/getSysParams`,
      //method:'POST',
      data: { bigtype: 'SYSTEM', smalltype: 'INTRODUCE' },
      login: false,
      success(result) {
        if (result.data.data.status == '0') {
          that.setData({
            introduce: result.data.data.msg
          })
        } else {
          console.log(JSON.stringify(result.data.data));
        }
      },
      fail(error) {
        console.log('request fail', error);
      }
    })
  },
  //获取通知信息
  getNotice() {
    var that = this
    qcloud.request({
      url: `${config.service.host}/weapp/getSysParams`,
      //method:'POST',
      data: { bigtype: 'SYSTEM', smalltype: 'NOTICE' },
      login: false,
      success(result) {
        if (result.data.data.status == '0') {
          that.setData({
            noticeList: result.data.data.msg
          })
        } else {
          console.log(JSON.stringify(result.data.data));
        }
      },
      fail(error) {
        console.log('request fail', error);
      }
    })
  },
  //获取介绍信息
  getMenu() {
    var that = this
    qcloud.request({
      url: `${config.service.host}/weapp/getSysParams`,
      //method:'POST',
      data: { bigtype: 'SYSTEM', smalltype: 'MENU' },
      login: false,
      success(result) {
        if (result.data.data.status == '0') {
          that.setData({
            functions: result.data.data.msg
          })
        } else {
          console.log(JSON.stringify(result.data.data));
        }
      },
      fail(error) {
        console.log('request fail', error);
      }
    })
  },
  tapIntroduce(e) {
    if (e.currentTarget.dataset.url) {
      wx.navigateTo({
        url: e.currentTarget.dataset.url
      })
    }
  }
})